#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
	char str[1001];
	int n;
	cin >> n;
	while (n--)
	{
		//memset(str, 0, sizeof(str));
		int sum = 0;
		cin >> str;
		int len = strlen(str);
		for (int i = 0; i < len; i++)
		{
			if (str[i] >= '0' && str[i] <= '9')
			{
				sum++;
			}
		}
		cout << sum << endl;
	}
	return 0;
}